unit uFormaPgto;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FMTBcd, Grids, DBGrids, StdCtrls, Mask, DBCtrls, DB, SqlExpr,
  Provider, DBClient, Buttons;

type
  TfFormaPgto = class(TForm)
    cdsForma: TClientDataSet;
    dsForma: TDataSetProvider;
    dstForma: TDataSource;
    sForma: TSQLDataSet;
    sFormaID_FORMAPGTO: TIntegerField;
    sFormaDESC_FORMAPGTO: TStringField;
    cdsFormaID_FORMAPGTO: TIntegerField;
    cdsFormaDESC_FORMAPGTO: TStringField;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    DBGrid1: TDBGrid;
    BitBtn1: TBitBtn;
    btnAdiconar: TBitBtn;
    btnGravar: TBitBtn;
    procedure btnAdiconarClick(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fFormaPgto: TfFormaPgto;

implementation

uses UDM;

{$R *.dfm}

procedure TfFormaPgto.btnAdiconarClick(Sender: TObject);
begin
  if not(dstForma.DataSet.Active) then
     dstForma.DataSet.open;
  dstForma.DataSet.Append;
  DBEdit2.SetFocus;

end;

procedure TfFormaPgto.btnGravarClick(Sender: TObject);
begin
  if (dstForma.State in [dsInsert]) then
  begin
    if dm.c_6_genid.Active then
      dm.c_6_genid.Close;
    dm.c_6_genid.CommandText := 'SELECT CAST(GEN_ID(FORMA_PGTO, 1) '+
     'AS INTEGER) AS CODIGO FROM RDB$DATABASE';
    dm.c_6_genid.Open;

    cdsFormaID_FORMAPGTO.AsInteger := dm.c_6_genid.Fields[0].AsInteger;
    cdsFormaDESC_FORMAPGTO.AsString := DBEdit2.Text;
    cdsForma.ApplyUpdates(0) ;

  end;
  if (dstForma.State in [dsEdit]) then
  begin
    cdsFormaDESC_FORMAPGTO.AsString := DBEdit2.Text;
    cdsForma.ApplyUpdates(0) ;

  end;

end;

procedure TfFormaPgto.BitBtn1Click(Sender: TObject);
begin
  cdsForma.Cancel;
end;

end.
